import { createRouter, createWebHistory } from 'vue-router';
import Login from '../components/Login.vue';
import Register from '../components/Register.vue';
import { ElMessage } from 'element-plus';

import Home from '../components/Home.vue';
import VideoPlayer from '../components/VideoPlayer.vue';
import Organization from '../components/Organization.vue';
import OrganizationAdmin from '../components/OrganizationAdmin.vue';
import TrainPlan from '../components/TrainPlan.vue';
import Question from '../components/Question.vue';
import StuLogin from '../components/student/StuLogin.vue';
import StuRegister from '../components/student/StuRegister.vue';
import StuHome from '../components/student/StuHome.vue';
import StuIntroduction from '../components/student/StuIntroduction.vue';
const routes = [
    {
      path:'/login',
      name: 'Login',
      component: Login
    },
    {
        path:'/register',
        name: 'Register',
        component: Register
    },
    {
      path:'/Home',
      name: 'Home',
      component: Home,
      children: [
        {
          path: 'videoPlayer',
          name: 'VideoPlayer',
          component: VideoPlayer
        },
        {
          path: 'organization',
          name: 'Organization',
          component: Organization
        },
        {
          path: 'organizationAdmin',
          name: 'OrganizationAdmin',
          component: OrganizationAdmin
        },
        {
          path: 'plan',
          name: 'TrainPlan',
          component: TrainPlan
        },
        {
          path: 'question',
          name: 'Question',
          component: Question
        },
      ]
    },
    {
      path:'/stuLogin',
      name: 'StuLogin',
      component: StuLogin
    },
    {
      path:'/stuRegister',
      name: 'StuRegister',
      component: StuRegister
    },
    {
      path:'/stuHome',
      name: 'StuHome',
      component: StuHome,
      children:[
        {
          path:'introduction',
          name: 'StuIntroduction',
          component: StuIntroduction
        }
      ]
    }

  
]
const router = createRouter({
    history: createWebHistory(),
    routes,
  });
  //添加全局前置守卫
// router.beforeEach((to, from, next) => {
//     const isUserLoggedIn = () => {
//         const loginStatus = sessionStorage.getItem('isLoggedIn');
//         return loginStatus === 'true';
//     };
  
//     const publicPages = ['Login', 'Register']; // 定义公开页面（不需要登录就能访问的页面）列表
//     const isPublicPage = publicPages.includes(to.name);
  
//     if (!isPublicPage &&!isUserLoggedIn()) {
//         // 如果要访问的不是公开页面且用户未登录
//         ElMessage({
//             message: '请先登录',
//             type: 'warning',
//         });
//         next({ name: 'Login' }); // 重定向到登录页面
//     } else {
//         next(); // 继续路由跳转
//     }
//   });
  export default router;